<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>宿舍管理</title>
    <link type="text/css" href="css/base.css" rel="stylesheet"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/menu.js"></script>
    <script src='<%=basePath%>dwr/util.js' type="text/javascript"></script>
    <script src='<%=basePath%>dwr/engine.js' type="text/javascript"></script>
    <script src='<%=basePath%>dwr/interface/dormitoryService.js' type="text/javascript"></script>
    <!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
    <script type="text/javascript">
        $(document).ready(function () {
            dormitoryService.findByCampus('${campus}',getDormitory);
        });

        function getDormitory(thelist) {
            var select_list = '<option value="" style="text-align: center">' + '------请选择------' + '</option>';
            for (var i = 0; i < thelist.length; i++) {
                select_list += '<option style="text-align: center" value="' + thelist[i].id + '">'
                        + thelist[i].dormitoryId + "</option>";
            }
            $("#dormitoryList1").html(select_list);
        }

        function topage(page) {
            var form = document.getElementById("myform");
            document.getElementById("page")
                    .setAttribute("value", page);
            form.submit();
        }
        /*
         *全选
         */
        function allselect(allobj, items) {
            var state = allobj.checked;
            if (items.length > 0) {
                for (var i = 0; i < items.length; i++) {
                    if (!items[i].disabled && i<4) {
                        items[i].checked = state;
                    }
                }
            } else {
                if (!items.disabled)items.checked = state;
            }
        }
        function actionEvent() {
            var form = document.getElementById("myform");
            var count = ValidateIsSelect(form.all, form.stuIds) ;
            if (count > 4) {
                alert("一个宿舍最多只能住四位学生，请勿选择多于4条记录！");
            } else if(count>0 && count<=4){
                form.action = "Student!setDormitory.action";
                form.submit();
            }else{
                alert("请选择要操作的记录！");
            }
        }
        /*
         *判断是否选择了记录
         */
        function ValidateIsSelect(allobj, items) {
            if (items.length > 0) {
                var count = 0;
                for (var i = 0; i < items.length; i++) {
                    if (items[i].checked) {
                        ++count;
                    }
                }
                return count;
            } else {
                if (items.checked)return 1;
            }
            return count;
        }

    </script>
</head>

<body>
<%@ include file="/page/share/menu.jsp" %>

<div id="content" style="width: 1000px;margin-left: 17%;">
    <form method="post" action="Student!findNoDormitory.action" align="center" id="myform">
        <input type="hidden" name="page" value="1" id="page"/>
        <table align="center"
               style="margin:-5px 0px 0px 0px;;background: #114a93;opacity:0.9;font-family: '微软雅黑',serif;color: linen;width:
    1000px;text-align: center">
            <thead align="center">
            <tr>
                <td>
                    当前校区：
                </td>
                <td>
                    ${campus}
                </td>
            </tr>
            <tr>
                <td>
                    分配宿舍：
                </td>
                <td>
                    <select name="dormitory" style="height: 23px;margin: 2px auto;  width: 150px;" id="dormitoryList1">
                    </select>
                </td>
            </tr>
            <tr>
                <th>
                    <input type="checkbox" name="all" onclick="allselect(this,this.form.stuIds)" style="margin-left: -10px;"/>  全选
                </th>
                <th>
                    学 号
                </th>
                <th>
                    离校时间
                </th>
                <th>
                    电 话
                </th>
                <th>
                    性 别
                </th>
                <th>
                    姓 名
                </th>
                <th>
                    专 业
                </th>
            </tr>
            </thead>
            <s:iterator value="pageView.records" var="s">
                <tr align="center">
                    <td>
                        <input type="checkbox" name="stuIds" value="${s.studentId}"/>
                    </td>
                    <td>
                            <s:property value="#s.studentId"/>
                        &nbsp;
                    <td>
                        <fmt:formatDate value="${s.leaveDate}" pattern="yyyy-MM-dd"/>
                        &nbsp;
                    </td>
                    <td>
                        <s:property value="#s.phone"/>
                        &nbsp;
                    </td>
                    <td>
                        <s:property value="#s.sex"/>
                        &nbsp;
                    </td>
                    <td>
                        <s:property value="#s.studentName"/>
                        &nbsp;
                    </td>
                    <td>
                        <s:property value="#s.major.majorName"/>
                        &nbsp;
                    </td>
                </tr>
            </s:iterator>
            <tr>
                <td>
                    <input onclick="actionEvent()" type="submit" name="tijiao" value="提交" style="width: 100px;cursor: pointer;"/>
                </td>
            </tr>
        </table>
        <table align="center" style="font-family: '微软雅黑',serif;text-align: center">
            <tr>
                <td colspan="4" bgcolor="#114a93" align="center" style="width:600px;word-spacing:10pt;padding-right: 10px;height: 20px;">
                    <%@ include file="/page/share/fenye.jsp" %>
                </td>
            </tr>
        </table>
    </form>
</div>


<div id="footer">
    <p style="text-align: center;color: #757575;padding: 20px 0px 0px 0px; font:12px;">Copyright © 2010-2013 蓝天白云团队
        版权所有</p>
</div>
</body>
</html>